package com.dkm.ec.cart.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.cart.domain.CartItem;
import com.dkm.ec.cart.persistence.dao.CartItemQueryDao;
import com.dkm.ec.cart.persistence.entity.CartItemPo;
import com.dkm.ec.cart.repository.CartItemRepository;

/**
 * 对象功能:购物车项目 Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-05-17 23:33:18
 */
@Repository
public class CartItemRepositoryImpl extends AbstractRepository<String, CartItemPo,CartItem> implements CartItemRepository{
	  
	@Resource
	private  CartItemQueryDao cartItemQueryDao;

	public CartItem newInstance() {
		CartItemPo po = new CartItemPo();
		CartItem cartItem = SpringHelper.getBean(CartItem.class);
		cartItem.setData(po);
		return cartItem;
	}

	public CartItem newInstance(CartItemPo po) {
		CartItem cartItem = SpringHelper.getBean(CartItem.class);
		cartItem.setData(po);
		return cartItem;
	} 
	
	@Override
	protected IQueryDao<String, CartItemPo> getQueryDao() {
		return cartItemQueryDao;
	}

	@Override
	public List<CartItemPo> findByPartyId(String id) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("partyId", id);
		return cartItemQueryDao.findByKey("findByPartyId", params);
	}

	@Override
	public List<CartItemPo> findByIdsLeft(String carItemIds) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("carItemIds", carItemIds);
		return cartItemQueryDao.findByKey("findByIdsLeft", params);
	}

	@Override
	public List<CartItemPo> findShopByPartyId(String userId,String shopId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("partyId", userId);
		params.put("shopId", shopId);
		return cartItemQueryDao.findByKey("findShopByPartyId", params);
	}

	@Override
	public Integer findByItemByCarId(String cartId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("whereSql", "item.cart_id_='"+cartId+"'");
		return cartItemQueryDao.count(params);
	}

	@Override
	public List<CartItemPo> findShopByCartItemId(String carItemIds, String shopId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("carItemIds", carItemIds);
		params.put("shopId", shopId);
		return cartItemQueryDao.findByKey("findShopByCartItemId", params);
	}
	
}
